// type EnvType = 'dev' | 'qa' | 'production' | 'local';

const path = require('path');

function getEnv() {
    const deployEnv = process.env?.APP_DEPLOY_ENV;
    return deployEnv;
}

function getCurCwd() {
    const currentWorkingDirectory = process.cwd();
    return currentWorkingDirectory;
}

function pathResolve(dir) {
    return path.resolve(getCurCwd(), dir);
}

function getConfig() {
    const configFilePath = path.join(getCurCwd(), 'config/index.js');
    const config = require(configFilePath);
    const env = getEnv();
    return config[env] ?? {};
}

function getPackageJson() {
    const configFilePath = path.join(getCurCwd(), 'package.json');
    const packageInfo = require(configFilePath);
    return packageInfo;
}

/**
 * 
 * @returns config/index.js/cdnUrl
 */
function getPublicPath() {
    const configFilePath = path.join(getCurCwd(), 'config/index.js');
    const config = require(configFilePath);
    const env = getEnv();
    return `${config[env]?.cdnUrl || ''}/`;
}

/**
 * 
 * @returns static/jxjy-template
 */
function getAssetPath() {
    const configFilePath = path.join(getCurCwd(), 'package.json');
    const packageInfo = require(configFilePath);
    const assetDir = `static/${packageInfo.name}`;
    return assetDir;
}

module.exports =  { getPackageJson,getEnv, getCurCwd, getPublicPath, pathResolve, getAssetPath, getConfig };
